package cn.ava.ymcc.utils;

import cn.ava.ymcc.dto.LoginTokenInfoDto;
import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;


public class LoginInfoContextUtil {

    /**
     * 获取登录用户上下文信息
     * @return
     */
    public static LoginTokenInfoDto getLoginContext(){
        SecurityContext context = SecurityContextHolder.getContext();
        AssertUtil.isTrue(context.getAuthentication().isAuthenticated(),"请先登录");
        return JSONObject.parseObject(context.getAuthentication().getPrincipal().toString(),LoginTokenInfoDto.class);
    }
}